
-- --------------------------------------------------
-- Entity Designer DDL Script for SQL Server 2005, 2008, and Azure
-- --------------------------------------------------
-- Date Created: 10/23/2012 23:57:58
-- Generated from EDMX file: D:\Job\It Skill\Projects\SaleSoft\SaleSoftMVC\SaleSoft\SaleSoft\Models\SaleSoft.edmx
-- --------------------------------------------------

SET QUOTED_IDENTIFIER OFF;
GO
USE [DATA_SALE];
GO
IF SCHEMA_ID(N'dbo') IS NULL EXECUTE(N'CREATE SCHEMA [dbo]');
GO

-- --------------------------------------------------
-- Dropping existing FOREIGN KEY constraints
-- --------------------------------------------------

IF OBJECT_ID(N'[dbo].[FK_ct_donhang_ds_donhang]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[ct_donhang] DROP CONSTRAINT [FK_ct_donhang_ds_donhang];
GO
IF OBJECT_ID(N'[dbo].[FK_ct_donhang_ds_webmau]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[ct_donhang] DROP CONSTRAINT [FK_ct_donhang_ds_webmau];
GO
IF OBJECT_ID(N'[dbo].[FK_ds_banner_loai_banner]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[ds_banner] DROP CONSTRAINT [FK_ds_banner_loai_banner];
GO
IF OBJECT_ID(N'[dbo].[FK_ds_chitietnhomquantri_ds_nhomquantri]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[ct_nhomquantri] DROP CONSTRAINT [FK_ds_chitietnhomquantri_ds_nhomquantri];
GO
IF OBJECT_ID(N'[dbo].[FK_ds_chitietnhomquantri_ds_quyenquantri]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[ct_nhomquantri] DROP CONSTRAINT [FK_ds_chitietnhomquantri_ds_quyenquantri];
GO
IF OBJECT_ID(N'[dbo].[FK_ds_hotrotructuyen_loai_hotrotructuyen]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[ds_hotrotructuyen] DROP CONSTRAINT [FK_ds_hotrotructuyen_loai_hotrotructuyen];
GO
IF OBJECT_ID(N'[dbo].[FK_ds_menu_loai_menu]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[ds_menu] DROP CONSTRAINT [FK_ds_menu_loai_menu];
GO
IF OBJECT_ID(N'[dbo].[FK_ds_nhanvienquanly_ds_nhomquantri]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[ds_nhanvienquanly] DROP CONSTRAINT [FK_ds_nhanvienquanly_ds_nhomquantri];
GO
IF OBJECT_ID(N'[dbo].[FK_ds_noidungweb_loai_noidung]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[ds_noidungweb] DROP CONSTRAINT [FK_ds_noidungweb_loai_noidung];
GO
IF OBJECT_ID(N'[dbo].[FK_ds_webmau_loai_web]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[ds_webmau] DROP CONSTRAINT [FK_ds_webmau_loai_web];
GO

-- --------------------------------------------------
-- Dropping existing tables
-- --------------------------------------------------

IF OBJECT_ID(N'[dbo].[ct_donhang]', 'U') IS NOT NULL
    DROP TABLE [dbo].[ct_donhang];
GO
IF OBJECT_ID(N'[dbo].[ct_nhomquantri]', 'U') IS NOT NULL
    DROP TABLE [dbo].[ct_nhomquantri];
GO
IF OBJECT_ID(N'[dbo].[ds_banner]', 'U') IS NOT NULL
    DROP TABLE [dbo].[ds_banner];
GO
IF OBJECT_ID(N'[dbo].[ds_donhang]', 'U') IS NOT NULL
    DROP TABLE [dbo].[ds_donhang];
GO
IF OBJECT_ID(N'[dbo].[ds_hotrotructuyen]', 'U') IS NOT NULL
    DROP TABLE [dbo].[ds_hotrotructuyen];
GO
IF OBJECT_ID(N'[dbo].[ds_menu]', 'U') IS NOT NULL
    DROP TABLE [dbo].[ds_menu];
GO
IF OBJECT_ID(N'[dbo].[ds_nhanvienquanly]', 'U') IS NOT NULL
    DROP TABLE [dbo].[ds_nhanvienquanly];
GO
IF OBJECT_ID(N'[dbo].[ds_nhomquantri]', 'U') IS NOT NULL
    DROP TABLE [dbo].[ds_nhomquantri];
GO
IF OBJECT_ID(N'[dbo].[ds_noidungweb]', 'U') IS NOT NULL
    DROP TABLE [dbo].[ds_noidungweb];
GO
IF OBJECT_ID(N'[dbo].[ds_quyenquantri]', 'U') IS NOT NULL
    DROP TABLE [dbo].[ds_quyenquantri];
GO
IF OBJECT_ID(N'[dbo].[ds_webmau]', 'U') IS NOT NULL
    DROP TABLE [dbo].[ds_webmau];
GO
IF OBJECT_ID(N'[dbo].[loai_banner]', 'U') IS NOT NULL
    DROP TABLE [dbo].[loai_banner];
GO
IF OBJECT_ID(N'[dbo].[loai_hotrotructuyen]', 'U') IS NOT NULL
    DROP TABLE [dbo].[loai_hotrotructuyen];
GO
IF OBJECT_ID(N'[dbo].[loai_menu]', 'U') IS NOT NULL
    DROP TABLE [dbo].[loai_menu];
GO
IF OBJECT_ID(N'[dbo].[loai_noidungweb]', 'U') IS NOT NULL
    DROP TABLE [dbo].[loai_noidungweb];
GO
IF OBJECT_ID(N'[dbo].[loai_web]', 'U') IS NOT NULL
    DROP TABLE [dbo].[loai_web];
GO
IF OBJECT_ID(N'[dbo].[sysdiagrams]', 'U') IS NOT NULL
    DROP TABLE [dbo].[sysdiagrams];
GO

-- --------------------------------------------------
-- Creating all tables
-- --------------------------------------------------

-- Creating table 'ct_donhang'
CREATE TABLE [dbo].[ct_donhang] (
    [id_ct_donhang] int IDENTITY(1,1) NOT NULL,
    [id_donhang] int  NULL,
    [id_webmau] int  NULL
);
GO

-- Creating table 'ds_banner'
CREATE TABLE [dbo].[ds_banner] (
    [id_banner] int IDENTITY(1,1) NOT NULL,
    [tenbanner] nvarchar(100)  NULL,
    [urlbanner] nvarchar(500)  NULL,
    [hinhbanner] nvarchar(50)  NULL,
    [id_loaibanner] int  NULL,
    [trangthai] int  NULL
);
GO

-- Creating table 'ds_donhang'
CREATE TABLE [dbo].[ds_donhang] (
    [id_donhang] int IDENTITY(1,1) NOT NULL,
    [tendonhang] nvarchar(100)  NULL,
    [ngaydathang] datetime  NULL,
    [tinhtrang] int  NULL,
    [gia] bigint  NULL
);
GO

-- Creating table 'ds_hotrotructuyen'
CREATE TABLE [dbo].[ds_hotrotructuyen] (
    [id_hotrotructuyen] int IDENTITY(1,1) NOT NULL,
    [tenhotrotructuyen] nvarchar(50)  NULL,
    [id_loaihotrotructuyen] int  NULL,
    [trangthai] int  NULL
);
GO

-- Creating table 'ds_menu'
CREATE TABLE [dbo].[ds_menu] (
    [id_menu] int IDENTITY(1,1) NOT NULL,
    [tenmenu] nvarchar(50)  NULL,
    [urlmenu] nvarchar(255)  NULL,
    [trangthai] int  NULL,
    [id_loaimenu] int  NULL
);
GO

-- Creating table 'ds_nhanvienquanly'
CREATE TABLE [dbo].[ds_nhanvienquanly] (
    [id_nhanvien] int IDENTITY(1,1) NOT NULL,
    [tendangnhap] varchar(20)  NULL,
    [matkhau] varchar(200)  NULL,
    [id_nhomquantri] int  NULL,
    [trangthai] int  NULL
);
GO

-- Creating table 'ds_nhomquantri'
CREATE TABLE [dbo].[ds_nhomquantri] (
    [id_nhomquantri] int IDENTITY(1,1) NOT NULL,
    [tennhomquantri] varchar(50)  NULL,
    [ghichu] varchar(200)  NULL
);
GO

-- Creating table 'ds_noidungweb'
CREATE TABLE [dbo].[ds_noidungweb] (
    [id_noidungweb] int  NOT NULL,
    [tieude] nvarchar(255)  NULL,
    [noidung] nvarchar(max)  NULL,
    [ngaycapnhat] datetime  NULL,
    [tomtatnoidung] nvarchar(255)  NULL,
    [urlhinhanh] nvarchar(255)  NULL,
    [id_loainoidung] int  NULL,
    [trangthai] int  NULL
);
GO

-- Creating table 'ds_quyenquantri'
CREATE TABLE [dbo].[ds_quyenquantri] (
    [id_quyenquantri] int IDENTITY(1,1) NOT NULL,
    [tenquyen] varchar(50)  NULL,
    [mota] varchar(200)  NULL
);
GO

-- Creating table 'ds_webmau'
CREATE TABLE [dbo].[ds_webmau] (
    [id_webmau] int  NOT NULL,
    [tenwebmau] nvarchar(50)  NULL,
    [mota] nvarchar(255)  NULL,
    [urlhinh] nvarchar(255)  NULL,
    [urlthumucweb] nvarchar(50)  NULL,
    [gia] int  NULL,
    [id_loaiweb] int  NULL,
    [ngaycapnhat] datetime  NULL
);
GO

-- Creating table 'loai_banner'
CREATE TABLE [dbo].[loai_banner] (
    [id_loaibanner] int IDENTITY(1,1) NOT NULL,
    [tenloaibanner] nvarchar(50)  NULL
);
GO

-- Creating table 'loai_hotrotructuyen'
CREATE TABLE [dbo].[loai_hotrotructuyen] (
    [id_loaihotrotructuyen] int  NOT NULL,
    [tenloaihotro] nvarchar(50)  NULL
);
GO

-- Creating table 'loai_menu'
CREATE TABLE [dbo].[loai_menu] (
    [id_loaimenu] int IDENTITY(1,1) NOT NULL,
    [tenloaimenu] nvarchar(50)  NULL
);
GO

-- Creating table 'loai_web'
CREATE TABLE [dbo].[loai_web] (
    [id_loaiweb] int  NOT NULL,
    [tenloaiweb] nvarchar(255)  NULL
);
GO

-- Creating table 'ct_nhomquantri'
CREATE TABLE [dbo].[ct_nhomquantri] (
    [id_chitietnhomquantri] int IDENTITY(1,1) NOT NULL,
    [id_nhomquantri] int  NULL,
    [id_quyenquantri] int  NULL
);
GO

-- Creating table 'loai_noidungweb'
CREATE TABLE [dbo].[loai_noidungweb] (
    [id_loainoidung] int IDENTITY(1,1) NOT NULL,
    [tenloai] nvarchar(50)  NULL
);
GO

-- Creating table 'sysdiagrams'
CREATE TABLE [dbo].[sysdiagrams] (
    [name] nvarchar(128)  NOT NULL,
    [principal_id] int  NOT NULL,
    [diagram_id] int IDENTITY(1,1) NOT NULL,
    [version] int  NULL,
    [definition] varbinary(max)  NULL
);
GO

-- --------------------------------------------------
-- Creating all PRIMARY KEY constraints
-- --------------------------------------------------

-- Creating primary key on [id_ct_donhang] in table 'ct_donhang'
ALTER TABLE [dbo].[ct_donhang]
ADD CONSTRAINT [PK_ct_donhang]
    PRIMARY KEY CLUSTERED ([id_ct_donhang] ASC);
GO

-- Creating primary key on [id_banner] in table 'ds_banner'
ALTER TABLE [dbo].[ds_banner]
ADD CONSTRAINT [PK_ds_banner]
    PRIMARY KEY CLUSTERED ([id_banner] ASC);
GO

-- Creating primary key on [id_donhang] in table 'ds_donhang'
ALTER TABLE [dbo].[ds_donhang]
ADD CONSTRAINT [PK_ds_donhang]
    PRIMARY KEY CLUSTERED ([id_donhang] ASC);
GO

-- Creating primary key on [id_hotrotructuyen] in table 'ds_hotrotructuyen'
ALTER TABLE [dbo].[ds_hotrotructuyen]
ADD CONSTRAINT [PK_ds_hotrotructuyen]
    PRIMARY KEY CLUSTERED ([id_hotrotructuyen] ASC);
GO

-- Creating primary key on [id_menu] in table 'ds_menu'
ALTER TABLE [dbo].[ds_menu]
ADD CONSTRAINT [PK_ds_menu]
    PRIMARY KEY CLUSTERED ([id_menu] ASC);
GO

-- Creating primary key on [id_nhanvien] in table 'ds_nhanvienquanly'
ALTER TABLE [dbo].[ds_nhanvienquanly]
ADD CONSTRAINT [PK_ds_nhanvienquanly]
    PRIMARY KEY CLUSTERED ([id_nhanvien] ASC);
GO

-- Creating primary key on [id_nhomquantri] in table 'ds_nhomquantri'
ALTER TABLE [dbo].[ds_nhomquantri]
ADD CONSTRAINT [PK_ds_nhomquantri]
    PRIMARY KEY CLUSTERED ([id_nhomquantri] ASC);
GO

-- Creating primary key on [id_noidungweb] in table 'ds_noidungweb'
ALTER TABLE [dbo].[ds_noidungweb]
ADD CONSTRAINT [PK_ds_noidungweb]
    PRIMARY KEY CLUSTERED ([id_noidungweb] ASC);
GO

-- Creating primary key on [id_quyenquantri] in table 'ds_quyenquantri'
ALTER TABLE [dbo].[ds_quyenquantri]
ADD CONSTRAINT [PK_ds_quyenquantri]
    PRIMARY KEY CLUSTERED ([id_quyenquantri] ASC);
GO

-- Creating primary key on [id_webmau] in table 'ds_webmau'
ALTER TABLE [dbo].[ds_webmau]
ADD CONSTRAINT [PK_ds_webmau]
    PRIMARY KEY CLUSTERED ([id_webmau] ASC);
GO

-- Creating primary key on [id_loaibanner] in table 'loai_banner'
ALTER TABLE [dbo].[loai_banner]
ADD CONSTRAINT [PK_loai_banner]
    PRIMARY KEY CLUSTERED ([id_loaibanner] ASC);
GO

-- Creating primary key on [id_loaihotrotructuyen] in table 'loai_hotrotructuyen'
ALTER TABLE [dbo].[loai_hotrotructuyen]
ADD CONSTRAINT [PK_loai_hotrotructuyen]
    PRIMARY KEY CLUSTERED ([id_loaihotrotructuyen] ASC);
GO

-- Creating primary key on [id_loaimenu] in table 'loai_menu'
ALTER TABLE [dbo].[loai_menu]
ADD CONSTRAINT [PK_loai_menu]
    PRIMARY KEY CLUSTERED ([id_loaimenu] ASC);
GO

-- Creating primary key on [id_loaiweb] in table 'loai_web'
ALTER TABLE [dbo].[loai_web]
ADD CONSTRAINT [PK_loai_web]
    PRIMARY KEY CLUSTERED ([id_loaiweb] ASC);
GO

-- Creating primary key on [id_chitietnhomquantri] in table 'ct_nhomquantri'
ALTER TABLE [dbo].[ct_nhomquantri]
ADD CONSTRAINT [PK_ct_nhomquantri]
    PRIMARY KEY CLUSTERED ([id_chitietnhomquantri] ASC);
GO

-- Creating primary key on [id_loainoidung] in table 'loai_noidungweb'
ALTER TABLE [dbo].[loai_noidungweb]
ADD CONSTRAINT [PK_loai_noidungweb]
    PRIMARY KEY CLUSTERED ([id_loainoidung] ASC);
GO

-- Creating primary key on [diagram_id] in table 'sysdiagrams'
ALTER TABLE [dbo].[sysdiagrams]
ADD CONSTRAINT [PK_sysdiagrams]
    PRIMARY KEY CLUSTERED ([diagram_id] ASC);
GO

-- --------------------------------------------------
-- Creating all FOREIGN KEY constraints
-- --------------------------------------------------

-- Creating foreign key on [id_donhang] in table 'ct_donhang'
ALTER TABLE [dbo].[ct_donhang]
ADD CONSTRAINT [FK_ct_donhang_ds_donhang]
    FOREIGN KEY ([id_donhang])
    REFERENCES [dbo].[ds_donhang]
        ([id_donhang])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_ct_donhang_ds_donhang'
CREATE INDEX [IX_FK_ct_donhang_ds_donhang]
ON [dbo].[ct_donhang]
    ([id_donhang]);
GO

-- Creating foreign key on [id_webmau] in table 'ct_donhang'
ALTER TABLE [dbo].[ct_donhang]
ADD CONSTRAINT [FK_ct_donhang_ds_webmau]
    FOREIGN KEY ([id_webmau])
    REFERENCES [dbo].[ds_webmau]
        ([id_webmau])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_ct_donhang_ds_webmau'
CREATE INDEX [IX_FK_ct_donhang_ds_webmau]
ON [dbo].[ct_donhang]
    ([id_webmau]);
GO

-- Creating foreign key on [id_loaibanner] in table 'ds_banner'
ALTER TABLE [dbo].[ds_banner]
ADD CONSTRAINT [FK_ds_banner_loai_banner]
    FOREIGN KEY ([id_loaibanner])
    REFERENCES [dbo].[loai_banner]
        ([id_loaibanner])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_ds_banner_loai_banner'
CREATE INDEX [IX_FK_ds_banner_loai_banner]
ON [dbo].[ds_banner]
    ([id_loaibanner]);
GO

-- Creating foreign key on [id_loaihotrotructuyen] in table 'ds_hotrotructuyen'
ALTER TABLE [dbo].[ds_hotrotructuyen]
ADD CONSTRAINT [FK_ds_hotrotructuyen_loai_hotrotructuyen]
    FOREIGN KEY ([id_loaihotrotructuyen])
    REFERENCES [dbo].[loai_hotrotructuyen]
        ([id_loaihotrotructuyen])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_ds_hotrotructuyen_loai_hotrotructuyen'
CREATE INDEX [IX_FK_ds_hotrotructuyen_loai_hotrotructuyen]
ON [dbo].[ds_hotrotructuyen]
    ([id_loaihotrotructuyen]);
GO

-- Creating foreign key on [id_loaimenu] in table 'ds_menu'
ALTER TABLE [dbo].[ds_menu]
ADD CONSTRAINT [FK_ds_menu_loai_menu]
    FOREIGN KEY ([id_loaimenu])
    REFERENCES [dbo].[loai_menu]
        ([id_loaimenu])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_ds_menu_loai_menu'
CREATE INDEX [IX_FK_ds_menu_loai_menu]
ON [dbo].[ds_menu]
    ([id_loaimenu]);
GO

-- Creating foreign key on [id_nhomquantri] in table 'ds_nhanvienquanly'
ALTER TABLE [dbo].[ds_nhanvienquanly]
ADD CONSTRAINT [FK_ds_nhanvienquanly_ds_nhomquantri]
    FOREIGN KEY ([id_nhomquantri])
    REFERENCES [dbo].[ds_nhomquantri]
        ([id_nhomquantri])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_ds_nhanvienquanly_ds_nhomquantri'
CREATE INDEX [IX_FK_ds_nhanvienquanly_ds_nhomquantri]
ON [dbo].[ds_nhanvienquanly]
    ([id_nhomquantri]);
GO

-- Creating foreign key on [id_loaiweb] in table 'ds_webmau'
ALTER TABLE [dbo].[ds_webmau]
ADD CONSTRAINT [FK_ds_webmau_loai_web]
    FOREIGN KEY ([id_loaiweb])
    REFERENCES [dbo].[loai_web]
        ([id_loaiweb])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_ds_webmau_loai_web'
CREATE INDEX [IX_FK_ds_webmau_loai_web]
ON [dbo].[ds_webmau]
    ([id_loaiweb]);
GO

-- Creating foreign key on [id_quyenquantri] in table 'ct_nhomquantri'
ALTER TABLE [dbo].[ct_nhomquantri]
ADD CONSTRAINT [FK_ds_chitietnhomquantri_ds_nhomquantri1]
    FOREIGN KEY ([id_quyenquantri])
    REFERENCES [dbo].[ds_nhomquantri]
        ([id_nhomquantri])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_ds_chitietnhomquantri_ds_nhomquantri1'
CREATE INDEX [IX_FK_ds_chitietnhomquantri_ds_nhomquantri1]
ON [dbo].[ct_nhomquantri]
    ([id_quyenquantri]);
GO

-- Creating foreign key on [id_quyenquantri] in table 'ct_nhomquantri'
ALTER TABLE [dbo].[ct_nhomquantri]
ADD CONSTRAINT [FK_ds_chitietnhomquantri_ds_quyenquantri1]
    FOREIGN KEY ([id_quyenquantri])
    REFERENCES [dbo].[ds_quyenquantri]
        ([id_quyenquantri])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_ds_chitietnhomquantri_ds_quyenquantri1'
CREATE INDEX [IX_FK_ds_chitietnhomquantri_ds_quyenquantri1]
ON [dbo].[ct_nhomquantri]
    ([id_quyenquantri]);
GO

-- Creating foreign key on [id_loainoidung] in table 'ds_noidungweb'
ALTER TABLE [dbo].[ds_noidungweb]
ADD CONSTRAINT [FK_ds_noidungweb_loai_noidung]
    FOREIGN KEY ([id_loainoidung])
    REFERENCES [dbo].[loai_noidungweb]
        ([id_loainoidung])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_ds_noidungweb_loai_noidung'
CREATE INDEX [IX_FK_ds_noidungweb_loai_noidung]
ON [dbo].[ds_noidungweb]
    ([id_loainoidung]);
GO

-- --------------------------------------------------
-- Script has ended
-- --------------------------------------------------